//
//  NetUser.m
//  CarCare
//
//  Created by ileo on 14-8-11.
//  Copyright (c) 2014年 baozun. All rights reserved.
//

#import "NetUser.h"
#import "AIUserInfo.h"
#import "MapHelper.h"
#import <sys/utsname.h>

@implementation NetUser

+(NetUser *)loginWithTel:(NSString *)tel code:(NSString *)code{
    return [__SELF request:@"/member/login" withParams:@{@"tel":tel,@"code":code} type:REQUEST_POST];
}

+(NetUser *)loginByLCWithTel:(NSString *)tel pwd:(NSString *)pwd{
    return [__SELF request:@"/autofun/login" withParams:@{@"username":tel, @"password":pwd} type:REQUEST_POST];
}

+(NetUser *)getUserInfo{
    return [__SELF request:@"/information/getuserinfo" withParams:@{@"lng":@(MAPMGR.userCoordinate.longitude),@"lat":@(MAPMGR.userCoordinate.latitude)} type:REQUEST_POST];
}

+(NetUser *)loginOut{
    return [__SELF request:@"/member/loginOut" withParams:@{@"token":USERINFO.token} type:REQUEST_POST];
}

+(NetUser *)pushUserLocInfo{
    NSString *token = USERINFO.token;
    if (!token) {
        token = @"";
    }
    NSString *ip = @"0.0.0.0";
    NSString *uuid = token;
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *dev = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    NSString *ios = [NSString stringWithFormat:@"iOS %0.1f",__IOS_V];
    return [__SELF request:@"/information/upload" withParams:@{@"uuid":uuid,@"ip":ip,@"token":token,@"model":dev,@"platform":ios,@"version":__APP_V} type:REQUEST_POST];
}

+(NetUser *)callMessageFromTel:(NSString *)tel
{
    return [__SELF request:@"/VerifyCode/VoiceVerifyCode" withParams:@{@"tel":tel} type:REQUEST_POST];
}

+(NetUser *)bindingAliWithRealName:(NSString *)realName alipay:(NSString *)alipay idCard:(NSString *)idCard{
    return [__SELF request:@"/information/aplipaybaseinfo" withParams:@{@"name":realName,@"alipay":alipay,@"idcard":idCard} type:REQUEST_POST];
}

+(NetUser *)setNewTel:(NSString *)newTel code:(NSString *)code{
    return [__SELF request:@"/setting/setNewTel" withParams:@{@"new_tel":newTel, @"code":code} type:REQUEST_POST];
}


+(NetUser *)setIcon:(UIImage *)icon{
    return [__SELF request:@"/setting/setImage" withParams:@{@"file":[ImageHelper dataWithImage:icon compressLength:40000]} type:REQUEST_POST];
}

+(NetUser *)setUserName:(NSString *)userName{
    return [__SELF request:@"/setting/setUsername" withParams:@{@"tel":USERINFO.tel, @"username":userName} type:REQUEST_POST];
}

-(NSDictionary *)requestCommonParams{
    if (![USERINFO.session isNotNil]) {
        return nil;
    }
    return @{@"userid":@(USERINFO.userID),@"session":USERINFO.session};
}

@end